import React, {Fragment, useEffect, useState} from 'react'
import {View,Text} from '@tarojs/components'
import store from "../../../../store";

export default function LeftNav({leftNavList}){
  const [currIficationNav,useCurrIficationNav] = useState(store.getState().currIficationNav)

  useEffect(() => {
    store.subscribe(changeState)
  },[])

  function changeCurrIficationNav(index){
    const action = {
      type: 'change_curr_ification_nav',
      index
    }
    store.dispatch(action)
  }
  function changeState (){
    useCurrIficationNav(store.getState().currIficationNav)
  }
  return (
    <Fragment>
      {
        leftNavList.map((item,index) => {
          return (
            <View className={`left_nav_item ${index === currIficationNav? 'is_ification_nav':''}`} onClick={() => {changeCurrIficationNav(index)}}>
              {item.text}
            </View>
          )
        })
      }

    </Fragment>

  )
}
